package org.doit.android.bobple.history;

import java.util.ArrayList;
import java.util.HashMap;

import org.doit.android.bobple.R;
import org.doit.android.bobple.base.BaseActivity;
import org.doit.android.bobple.common.ServerRequester;
import org.doit.android.bobple.common.ServerResponseJson;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;

/**
 * @author Choi HongKi
 *
 */
public class HistoryActivity extends BaseActivity {
	@Override
	protected void drawOnCreate(Bundle savedInstanceState) {
		inflateContentViewStub(R.layout.history);

		HashMap<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("user_id", "rogah0131@nhn.com"); // -_-/

		ServerResponseJson response = ServerRequester.request("individual/getRecentLunchHistory", paramMap);
		if (response.isSuccess()) {

			try {
				ListView lvHistory = (ListView)findViewById(R.id.hist_lv_history);
				ArrayList<History> historyList = new ArrayList<History>();

				JSONArray values = response.getValues();
				for (int index = 0; index < values.length(); index++) {
					JSONObject value = values.getJSONObject(index);
					historyList.add(new History(value.getString("ymd"), value.getString("rstrtNm"), value.getInt("score")));
				}

				HistoryAdapter adapter = new HistoryAdapter(this, historyList);

				lvHistory.setAdapter(adapter);
			} catch (JSONException e) {
				Toast.makeText(this, "데이터 초기화 실패여유~ -_-/", 10);
			}
		} else {
			Toast.makeText(this, "값을 못 가져왔어라우~ -_-/", 10);
		}
	}
}